//
// Created by admin on 2023/1/30.
//

#ifndef BV_SERIAL_PORT_H
#define BV_SERIAL_PORT_H

#include "../utils/select.h"
#include <stdint.h>


namespace conn {

constexpr uint8_t HEAD0 = 0xE1;
constexpr uint8_t HEAD1 = 0x1E;

class SerialPort {

public:
    SerialPort(const char *name, int baud_rate);
    ~SerialPort();

    void notify_read_exit();

    ssize_t read(void *buf, size_t size);
    uint8_t sync();
    void read_bytes(uint8_t *buf, size_t n);

    void write(const void *buf, size_t size) const;

private:
    utils::Select m_select;
    int m_fd;
};

}

#endif //BV_SERIAL_PORT_H
